﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Agresso.Interface.Layer.Domain
{
    public class ProfitCentre
    {
        public long profit_centre_id;
        public string co_type = string.Empty;
        public string short_code = string.Empty;
        public string short_name = string.Empty;
        public string full_name = string.Empty;
        public string full_address = string.Empty;
        public string city = string.Empty;
        public string country = string.Empty;
        public string account_code = string.Empty;
        public string active = string.Empty;
        public string agr_description = string.Empty;
        public string agr_dim_value = string.Empty;
        public string agr_rel_value = string.Empty;
        public string ccc_dim_value = string.Empty;

        public string expense_account = string.Empty;
        public string client = string.Empty;

        public ProfitCentre CommissionManager = null;
        public DateTime created_date = new DateTime(1900, 1, 1);
        public DateTime modified_date = new DateTime(1900, 1, 1);


        public ProfitCentre() { }
        public ProfitCentre(long id) { profit_centre_id = id; }
        public ProfitCentre(bool isFromSoftmar, SqlDataReader rd)
        {
            if (!isFromSoftmar)
            {
                profit_centre_id = Convert.ToInt32(rd["profit_centre_id"]);
                agr_description = rd["agr_description"] is DBNull ? agr_description : rd["agr_description"].ToString();
                agr_dim_value = rd["agr_dim_value"] is DBNull ? agr_dim_value : rd["agr_dim_value"].ToString();
                agr_rel_value = rd["agr_rel_value"] is DBNull ? agr_rel_value : rd["agr_rel_value"].ToString();
                created_date = rd["created_date"] is DBNull ? created_date : Convert.ToDateTime(rd["created_date"]);
                client = rd["client"] is DBNull ? client : rd["client"].ToString();
                modified_date = rd["modified_date"] is DBNull ? modified_date : Convert.ToDateTime(rd["modified_date"]);
                ccc_dim_value = rd["ccc_dim_value"] is DBNull ? ccc_dim_value : rd["ccc_dim_value"].ToString();
                expense_account = rd["expense_account"] is DBNull ? expense_account : rd["expense_account"].ToString();
                CommissionManager = new ProfitCentre(rd["legal_entity_id"] is DBNull ? 0 : Convert.ToInt32(rd["legal_entity_id"]));
            }
            co_type = rd["co_type"] is DBNull ? co_type : rd["co_type"].ToString();
            short_code = rd["short_code"] is DBNull ? short_code : rd["short_code"].ToString();
            short_name = rd["short_name"] is DBNull ? short_name : rd["short_name"].ToString();
            full_name = rd["full_name"] is DBNull ? full_name : rd["full_name"].ToString();
            full_address = rd["full_address"] is DBNull ? full_address : rd["full_address"].ToString();
            city = rd["city"] is DBNull ? city : rd["city"].ToString();
            country = rd["country"] is DBNull ? country : rd["country"].ToString();
            account_code = rd["account_code"] is DBNull ? account_code : rd["account_code"].ToString();
            active = rd["active"] is DBNull ? active : rd["active"].ToString();
        }

        public bool IsValidProfitCentre()
        {
            //return agr_dim_value != "" && expense_account != "" && ccc_dim_value != "" && client != "";
            return
                profit_centre_id > 0 &&
                agr_dim_value != string.Empty;
        }
    }

}
